from django.shortcuts import render, redirect
from django.views.generic import View
from apps.home_page.models import UdwUser
#登录注册


class Login(View):
    def get(self, request):
        return render(request, 'login.html')


    def post(self, request):
        phone = request.POST.get('phone')
        password = request.POST.get('password')
        print(phone)
        if not all([phone, password]):
            return render(request, 'login.html', {'error': '信息不完整'})
        if not UdwUser.objects.filter(user_phone=phone, user_password=password).exists():
            return render(request, 'login.html', {'error': '账号密码错误'})
        request.session['id'] = UdwUser.objects.get(user_phone=phone, user_password=password).user_id
        return redirect('home_page:index')



# class Login(View):
#     def get(self, request):
#         return render(request, 'login2.html')
#
#     def post(self, request):
#         pass